package com.shababeach.travel.controller;

import com.shababeach.travel.dto.Result;
import com.shababeach.travel.entity.Location;
import com.shababeach.travel.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 位置信息控制器
 */
@RestController
@RequestMapping("/locations")
public class LocationController {

    @Autowired
    private LocationService locationService;

    /** 分页查询位置信息 */
    @GetMapping("/page")
    public Result<Page<Location>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) Integer typeId,
            @RequestParam(required = false) String keyword) {
        Pageable pageableRequest = PageRequest.of((current-1), size);
        Page<Location> pageData = locationService.pageList(pageableRequest, typeId, keyword);
        return Result.success(pageData);
    }

    /** 获取推荐位置列表 */
    @GetMapping("/recommend")
    public Result<List<Location>> getRecommendLocations() {
        return Result.success(locationService.getRecommendLocations());
    }

     /** 获取指定类型位置列表 */
    @GetMapping("/byType")
    public Result<List<Location>> getLocationsByType(@RequestParam Integer typeId) {
        return Result.success(locationService.getLocationsByType(typeId));
    }

    /** 获取位置详情 */
    @GetMapping("/{id}")
    public Result<Location> getLocationDetail(@PathVariable Integer id) {
        locationService.increaseViewCount(id);
        return Result.success(locationService.getLocationDetail(id));
    }
} 